package com.javabasic.algorithm.leetcode;

import java.util.Iterator;
import java.util.Set;
import java.util.TreeMap;

/**
 * @author mir.xiong
 * @version 1.0
 * @description 简单题
 * @see [1217. Minimum Cost to Move Chips to The Same Position](https://leetcode-cn.com/problems/minimum-cost-to-move-chips-to-the-same-position/)
 * @since Created by work on 2021/12/4 5:58 下午
 */
public class MinimumCostToMoveChipsToTheSamePosition {


    /**
     * 逻辑转换
     * 实际上我们其实就是分为奇偶两堆而已，然后判断两堆中较小堆的数量，即为结果
     * @param position
     * @return
     */
    public int minCostToMoveChips(int[] position) {
        int len = position.length;
        int maxValue = Integer.MIN_VALUE;
        for (int i = 0; i < len; i++) {
            if (maxValue < position[i]) {
                maxValue = position[i];
            }
        }
        int maxSize = 0, secondMaxSize = 0;
        for (int i = 0; i < len; i++) {
            if (((maxValue-position[i]) & 1) == 1) {
                secondMaxSize++;
            } else {
                maxSize ++;
            }
            System.out.println("maxSize = " + maxSize + " secondMaxSize = " + secondMaxSize);
        }
        return Math.min(maxSize,secondMaxSize);
    }
}
